<?php
session_start();
$day = null;
$month = null;
$year = null;
if(isset($_GET['day'])){
	$day = $_GET['day'];
}
if(isset($_GET['month'])){
	$month = $_GET['month'];
}
if(isset($_GET['year'])){
	$year = $_GET['year'];
}

$title="รายการเตรียมห้องพัก";
include ('header-admin.php');


$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 30;
$limit_start = ($page-1)*$limit_end;

function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
    $output = "";
    $total = ceil($count/$limit);
    $navi_start = $page-$range;
    $navi_end = $page+$range;
     
    $send .= (!empty($send))? "&" : NULL;
         
    if($navi_start <= 0) $navi_start = 1;
    if($navi_end >= $total) $navi_end = $total;

	//$day = $_POST['day'];
	//$month = $_POST['month'];
	//$year = $_POST['year'];
	$day = null;
	$month =  null;
	$year = null;
	
	if(isset($_GET['day']) || isset($_GET['month']) ||  isset($_GET['year'])){
		$day = $_GET['day'];
		$month = $_GET['month'];
	 	$year = $_GET['year'];	
	}

     
    if($page>1){
        $navi_back = $page-1;
        if($page > 2)
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>&laquo;</strong></a> ";
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>&#8249;</strong></a> ";
    }
    for($i = $navi_start; $i <= $navi_end; $i++){
        if($i == $page)
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
        else
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
    }
    if($page < $total){
        $navi_next = $page+1;
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>&#8250;</strong></a> ";
        if(($page+1) < $total)
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>&raquo;</strong></a>";
    }
    if($navi_start>$navi_end)
        $output .= "<a href=\"?" . $send . "day=".$day."&month=".$month."&year=".$year."&page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
    return $output;
}


$menu = array('แสดงรายการจองทั้งหมด','แสดงรายการจองที่ยังไม่ Confirm');

$userID=$_SESSION["HBD_USER"];
$countTopic=0;
if($userID == 1){
?>
<script language="javascript">
	function ConfirmChoice(id){
	answer = confirm("คุณแน่ใจว่าจะลบ ?")
		if (answer !=0)
			location = "doDeleteNews.php?newsID=" + id;
	}
</script>
<?}?>
<div id="center-block" class="main-content">
<img src="img/housekeeper_icon.png"/ id="img-block-content">
<div id="content-title-right">
		<h2 class="caption-header">รายการเตรียมห้องพัก สำหรับแม่บ้าน</h2>
		<span class="caption">ใช้สำหรับห้องพักหาดบ้านดินรีสอร์ท</span>
		<span class="right-button">
		   <form name="jump" method="GET" action="forHousekeeper.php?page=1">
			<select name="day" id="day" style="width: 50px">
		      <?
		      if($day == '')
		      {$day = date("d");}
				echo '<option value="">วัน</option>';
				for($i=1;$i<=31;$i++){
					if($day == $i)
						echo '<option value="' . $i . '" SELECTED>' . $i . '</option>';
					else
						echo '<option value="' . $i . '">' . $i . '</option>';
				}
				
		      ?>
			</select>
			<select name="month" id="month" style="width: 70px">
		      <?
		      if($month == '')
		      {$month = date("m");}
				$monthname = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
				echo '<option value="">เดือน</option>';
				$i=1;
				foreach($monthname as $month_text){
					if($month == $i)
						echo '<option value="' . $i . '" SELECTED>' . $month_text . '</option>';
					else
						echo '<option value="' . $i . '">' . $month_text . '</option>';
					$i++;
				}
		      ?>
			</select>
			<select name="year" id="year" style="width: 60px">
		      <?
		      if($year == '')
		      {$year = date("Y");}
				echo '<option value="">ปี</option>';
				for($i=2009;$i<=2050;$i++){
					if($year == $i)
						echo '<option value="' . $i . '" SELECTED>' . $i . '</option>';
					else
						echo '<option value="' . $i . '">' . $i . '</option>';
				}
					
		      ?>
			</select>
			&nbsp;<input type="submit" value="ค้นหา" class="button">
			</form>
				</span>
	</div>
	<script language="javascript">
	function printReportPage(){
		window.open('print.php?ref=p_hkeeper&day=<?php echo $day;?>&month=<?php echo $month;?>&year=<?php echo $year;?>', 'printpage', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=480')
                      return false;
	}
</script>

<div style="margin-top:-35px;" class="center"><a href="#" onclick="printReportPage();"><img src="./img/printer.png" alt="print" width="32px" height="32px"><span style="padding:5px 0 0 5px;">กดปุ่มเพื่อทำการพิมพ์ข้อมูลผ่านเครื่องพิมพ์</span></a>
	</div>
	<hr>
	
	<table summary="webboard about Datastrucutre learning" id="table">
		<thead>
		<tr class="odd">
			<th scope="col" abbr="reserv_begin">วันเข้าที่พัก</th>
			<th scope="col" abbr="room_id">ห้อง</th>
			<th scope="col" abbr="customer_name">ชื่อผู้จอง</th>
			<th scope="col" abbr="customer_name">เตียงเสริม</th>
			<th scope="col" abbr="customer_name">รายละเอียดอื่นๆ</th>
		</tr>	
		</thead>
		<tbody>
		<?
		//date funciton
		$begin_day = $day;
		$end_day = $day;
		$begin_month = $month;
		$end_month = $month;


		if($day == "" || !isset($day)){
			$begin_day = 1;
			$end_day = 31;
		}
		if($month == "" || !isset($month)){
			$begin_month = 1;
			$end_month = 12;
		}

		$beginquery = $year . "-" . $begin_month . "-" . $begin_day;
		$endquery = $year . "-" . $end_month . "-" . $end_day;

		if($day== "" && $month == "" && $year == "")
		{$datestring = "";}
		else
		{$datestring = "WHERE reserv_begin between '$beginquery' and '$endquery'";}

		$sql="SELECT reserv_begin,reserv_end,customer_name,customer_surname,reserv_etc,room_id,extra_bed
   FROM reservation
   INNER JOIN customer ON ( reservation.id = customer.id )
   " . $datestring . "ORDER BY reserv_begin ASC";

		if($day != ""){
			$choosetime = $year."-".$begin_month."-".$begin_day;
			$sql="SELECT reserv_begin,reserv_end,customer_name,customer_surname,reserv_etc,room_id,extra_bed
   FROM reservation
   INNER JOIN customer ON ( reservation.id = customer.id )
   WHERE reserv_begin = '$choosetime' ORDER BY reserv_begin ASC";
   }

	$sql;

	$result = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end);
	$count = mysql_num_rows($result);
	$total = mysql_num_rows(mysql_query($sql));
	$status = " ";
if($total > 0){
	while ($rs = mysql_fetch_array($result)){
		/*
if($rs['reserv_status']==0)$status = '<img src="img/unavaliable.png">';
		if($rs['reserv_status']==1)$status = '<img src="img/avaliable.png">';
		if($rs['reserv_status']==2)$status = '<img src="img/m_icon_printer.png">';
*/
		
		$a = date( 'd-m-Y', strtotime( $rs['reserv_begin']));
		$b = date( 'd-m-Y', strtotime( $rs['reserv_end']));
/* 		echo $a; */
/* 		$roomArray = explode(',',$rs['room_id']); */
/* 		foreach($roomArray as $room){ */
			echo '<tr>';
		echo '<td>' . $rs['reserv_begin'] .'</td>';
		echo '<td>' . $rs['room_id'] . '</td>';
		echo '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
		echo '<td>' . $rs['extra_bed'] . '</td>';
/* 		echo '<td>' . $status . '</td>'; */
		echo '<td>' . $rs['reserv_etc'] . '</td>';
/* 		} */
	}

echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, null) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
	?>
		</tbody>

	</table>
	</div>

<?
include ('footer.php');
?>